package complexity.cohesion;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

public class DirectoryTraversal {

	String packageFolderPath;
	File directoryName;
	protected List<String> files = new ArrayList<String>();
	protected List<String> javaFiles = new ArrayList<String>();
	
	
	public DirectoryTraversal()
	{}
	
	
	public DirectoryTraversal(File directoryName)
	{
		//DirectoryTraversal.directoryName = directoryName;
	}
	
	public List<String> getDirectoryFiles(String packageFolderPath)
	{
		directoryName = new File(packageFolderPath);
		
		
		if(directoryName.isDirectory())
		{
			String[] subNote = directoryName.list();
			for( int i = 0; i<subNote.length; i++ )
			{
				files.add(subNote[i]);				
			}	
		}
		return files;
	}
	
	public void getJavaSourceFunction(String packageFolderPath)
	{
		getDirectoryFiles(packageFolderPath);
		
		for(String s : files)
		{
			
			String[] tokens = s.split(Pattern.quote(File.separator));
			String[] findJava = tokens[tokens.length-1].split("\\.");
			if(findJava.length != 0)
			{
				if(findJava[findJava.length-1].equals("java"))
				{
					String javaSourcePath = packageFolderPath.concat("\\").concat(s);
					javaFiles.add(javaSourcePath);
				}
			}
		}
		
	}
	
	public List<String> getJavaSourceFileList(String packageFolderPath)
	{
		this.packageFolderPath = packageFolderPath;
		//return new ArrayList<File>();
		getJavaSourceFunction(packageFolderPath);
		return javaFiles;
	}
	
}
